package cn.zysuyuan.item.controller;

import cn.zysuyuan.common.entity.PageResult;
import cn.zysuyuan.item.entity.MedicinalProductBase;
import cn.zysuyuan.item.entity.ProductBase;
import cn.zysuyuan.item.service.WxProductBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author flypig
 * @version 1.0
 * @date 2019-12-17 12:45
 */

@Api(tags = "小程序产区产地")
@Controller
@RequestMapping("wxproductbase")
public class WxProductBaseController {

    @Autowired
    private WxProductBaseService wxProductBaseService;

    @ApiOperation(value = "小程序全部基地信息", tags = "小程序全部基地信息")
    @GetMapping("productBaseData")
    public ResponseEntity<PageResult<ProductBase>> select(@RequestParam(value = "pbname") String pbname) {
        PageResult<ProductBase> result = this.wxProductBaseService.select(pbname);
        if (CollectionUtils.isEmpty(result.getRows())) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "特定药材对应的所有基地信息",tags = "特定药材对应的所有基地信息")
    @GetMapping("medicinalPbData")
    public ResponseEntity<PageResult<MedicinalProductBase>> selectMedicinalPb(@RequestParam("id") String id) {
        PageResult<MedicinalProductBase> result = this.wxProductBaseService.selectMedicinalPb(id);
        if (CollectionUtils.isEmpty(result.getRows())) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result);
    }
}
